<template>
  <div class="content-wrap">
    <van-nav-bar title="交易设置" left-arrow @click-left="$router.go(-1)">
    </van-nav-bar>

    <div class="content">
      <van-cell-group class="checkGroup">
        <van-switch-cell v-model="closeRedBag" title="关闭红包功能" @change="editSetting('closeRedBag')" />
        <van-switch-cell v-model="closeTransfer" title="关闭转账功能" @change="editSetting('closeTransfer')" />
      </van-cell-group>
    </div>
  </div>
</template>

<script>
  import Socket from '../../utils/socket'
  import { mapState } from 'vuex'
  export default {
    name: 'transaction',
    data () {
      return {
        closeRedBag: false,
        closeTransfer: false
      }
    },
    computed: {
      ...mapState({
        userData: state => state.user.userData
      })
    },
    methods: {
      editSetting (type) {
        let flag = this[type] ? 1 : 2
        if (type === 'closeRedBag') {
          Socket.sendData('setUserOnRed', { status: flag }).then(() => {
            this.$store.commit('setObjAttr', { obj: 'userData', attr: 'OnRed', data: this[type] })
          })
        } else if (type === 'closeTransfer') {
          Socket.sendData('setUserOnMout', { status: flag }).then(() => {
            this.$store.commit('setObjAttr', { obj: 'userData', attr: 'OnMout', data: this[type] })
          })
        }
      }
    },
    created () {
      this.closeRedBag = this.userData.OnRed
      this.closeTransfer = this.userData.OnMout
    }
  }
</script>

<style scoped>

</style>
